home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # Apple Developer Technical Support
- #
- # AEDeamon
- # A small faceless background-only application for sending AppleEvents
- #
- # main.c - C Source
- #
- # Copyright © 1991 Apple Computer, Inc.
- # All rights reserved.
- #
- # Versions:
- # 1.0 08/91 C.K. Haun <TR>
- #
- # Components:
- # AEDeamonMain.c
- # AEDeamonAEvents.c
- # AEDeamonPPCStuff.c
- #
- # This is a faceless background process who's whole mission in
- # life is to send AppleEvents for code that can't (like the accompaning
- # AECDEV). It will send any AppleEvent it gets through it's PPC port.
- #
- # The main things to note are....
- # 1) Look at the SIZE resource for the flag settings you'll
- # need to let the Finder™ know that you only want to work
- # in the background.
- # 2) Notice that you really do have your own heap and your own
- # event loop. You can do anything a foreground application
- # can do, send AppleEvents, PPC stuff, anything else you'd
- # like EXCEPT a graphic interface.
- # 3) NOTE that no managers are started up. You cannot start up
- # Window, Menu, Dialogs, or anything else that
- # deals with the graphic interface. Just leave them out.
- # You CAN start up QuickDraw if you want to do some graphic
- # processing, but DO NOT draw to the screen, only use things
- # like offscreen grafports or GWorlds. Or you may
- # want to start it to use Random().....
- #
- # Of course, a backgrounder can be launched from the Finder™
- # with a double-click. However, if you'd like the backgrounder
- # to perform some useful service for your main application, driver,
- # DA, or whatever, you will want it running all the time.
- # The BEST way to insure this is to install the backgrounder in the
- # StartUp Items folder in the system folder. This will insure that
- # it is always launched, and it will also reduce memory fragmentation
- # since it will be installed at startup time. You can search for it
- # when you need it with IPCListPorts (see the PPC toolbox documentation
- # or the AECDEV code).
- # Optionally, you can use the LaunchApplication trap to launch it
- # when you need it, and kill it when you're done. But this could
- # cause some multiFinder heap fragmentation.
- #
- # And remember, it's a backgrounder, you can't see it. To kill it
- # use TaskIt or ProcDoggie.
- #
- # ---------------------------------------------------------------
- # Use this sample as a starting point, and adapt its' routines to
- # meet the specific needs of your project.
- # This sample will grow as more edition types are implemented,
- # periodically check AppleLink for a later, expanded sample.
- # This application is an example of the form of a Macintosh
- # application; it is NOT a template. It is NOT intended to be
- # used as a foundation for the next world-class, best-selling,
- # 600K application. A stick figure drawing of the human body may
- # be a good example of the form for a painting, but that does not
- # mean it should be used as the basis for the next Mona Lisa.
- #
- #
- ------------------------------------------------------------------------------*/
-
-
- #include "AEDaemon.h"
-
- extern MyPPCRecPtrDeamon ourPPCPtr;
- extern Ptr readBuffer;
- extern Handle dataHandle;
- Boolean gQuit = false;
- EventRecord ERecord;
- Boolean gHasAppleEvents;
- Boolean gReadAgain;
- Boolean gReadPending;
- unsigned long gMySleep = 200; /* Long time. Change this if */
- /* you'd like to do null processing. Just keep in mind that the */
- /* user does NOT know that you exisist, and if you are eating */
- /* up a bunch of time the user will not know why his or her */
- /* machine is slowing down. */
-
- main()
- {
- long ticksStart;
- /* We are NOT initializing any managers. We're in the background, with no */
- /* face, we can't use windows or dialogs or menus. If you need to talk to the */
- /* user you can post a notification, or launch an application to comunicate */
- /* Passing an AppleEvent in the launchapplication trap could do the */
- /* communication for you. */
-
- /* no nothing but events */
-
- InitAEStuff();
- /* now initialize our PPC connection so people know we're around */
- if(PPCInit() != noErr)ExitToShell(); /* bail */
- ourPPCPtr = (MyPPCRecPtrDeamon)NewPtrClear(sizeof(MyPPCRecDeamon));
- readBuffer = NewPtr(kOneK);
- dataHandle = NewHandle(nil); /* get an empty handle to start */
- /* check memory, bail if bad */
- if(ourPPCPtr == nil || dataHandle == nil || readBuffer== nil)ExitToShell();
- InformTheWorld();
- ticksStart = TickCount();
- /* no nothing but high level events */
- while (gQuit == false) {
- WaitNextEvent(highLevelEventMask, &ERecord, gMySleep, 0);
- if (ERecord.what == kHighLevelEvent)
- DoHighLevel(&ERecord);
- if (gReadPending)
- CollectLastData();
-
- }
- CloseOffTheWorld();
- }
-
- #undef __BUILDINGDEAMON__
- #undef __AEDMAIN__
-
-
-